package com.bit.demo;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/request")
public class RequestController {
    @RequestMapping("/login")
    public String login(String name) {
        return "接收到参数 name: " + name;
    }

    @RequestMapping("/r1")
    public String r1(Integer age) {
        return "接收到参数 age: " + age;
    }

    @RequestMapping("/r2")
    public String r2(int age) {
        return "接收到参数 age: " + age;
    }

    @RequestMapping("/r3")
    public String r3(String name, String password) {
        return "接收到参数 name: " + name + ", password: " + password;
    }

    @RequestMapping("/r4")
    public String r4(Person person) {
        return "接收到参数 Person: " + person;
    }

    @RequestMapping("/r5")
    public String r5(@RequestParam(value = "q", required = false) String keyword) {
        return "搜索词为: " + keyword;
    }

    @RequestMapping("/r6")
    public String r6(String[] arr) {
        return "数组: " + Arrays.toString(arr);
    }

    @RequestMapping("/r7")
    public String r7(@RequestParam List<String> list) {
        return "集合: " + Arrays.toString(list.toArray());
    }

    @RequestMapping("/r8")
    public String r8(@RequestBody Person person) {
        return "接受json数据: " + person;
    }
}
